package com.topone.Utils;

import com.topone.dataObject.TcUser;
import me.chanjar.weixin.mp.bean.result.WxMpUser;

import java.util.Arrays;
import java.util.Random;

public class ServiceUtils extends DaoUtils {

    public static String getRandomNumberByLength(int length) {
        String base = "0123456789";
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
    public static TcUser toWechat(WxMpUser user) {
        TcUser wechat = new TcUser();
        wechat.setUserId(KeyUntil.getUniqueKey());
        wechat.setOpenid(user.getOpenId());
        wechat.setCountry(user.getCountry());
        wechat.setGroupId(user.getGroupId());
        wechat.setHeadUrl(user.getHeadImgUrl());
        wechat.setLanguage(user.getLanguage());
        wechat.setUserName(user.getNickname());
        wechat.setProvince(user.getProvince());
        wechat.setRemark(user.getRemark());
        wechat.setGender(user.getSex());
        wechat.setSubscribe(user.getSubscribe());
        wechat.setSubscribeTime(user.getSubscribeTime());
        if (user.getTagIds() != null) {
            wechat.setTagIds(Arrays.toString(user.getTagIds()));
        }
        return wechat;
    }
}
